import {getUserLineList} from '@/api/linebody'
import {useEffect, useState} from 'react'

class SelectOpt {
  constructor(public Name = '',
              public LineName = '',
              public WorkShopName = '',
              public LastModifyBy = '',
              public Description = '',
  ) {
  }
}

export const useLineSelect = () => {
  const [opts, setOpts] = useState([])
  const [selectOpt, setSelectOpt] = useState<SelectOpt>(new SelectOpt())
  useEffect(() => {
    getUserLineList({keyName: '', lineType: -1}).then(res => {
      parseInt(res.Code) === 1 && setOpts(
        res.Result.map(e =>
          ({
            ...e, label: `${e.Description} | ${e.Name}`,  //  | ${e.LineId} | ${e.WorkShopName} | ${e.LastModifyBy}
            value: e.LineId
          })
        ))
    })
  }, [])

  return {
    lineSelectProps: {
      options: opts,
      onChange(val, opts) {
        setSelectOpt(opts)
      }
    },
    selectOpt
  }
}
